package cn.itcsat.demo.controller;

import cn.itcsat.demo.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.Date;

@Controller
public class HelloController {


    @GetMapping("heima60")
    public String sayHello(Model model){
        model.addAttribute("name","ldh");
        return "hello";
    }

    @GetMapping("show2")
    public String show2(Model model){
        User user = new User();
        user.setAge(21);
        user.setName("Jack Chen");
        user.setFriend(new User("李小龙", 30));

        model.addAttribute("user", user);
        return "show2";
    }


    @GetMapping("show3")
    public String show3(Model model){
       model.addAttribute("info","<h3>老司机</h3>");
        return "show3";
    }

    @GetMapping("show4")
    public String show4(Model model){
        User user = new User();
        user.setAge(21);
        user.setName("Jack Chen");
        user.setFriend(new User("李小龙", 30));

        model.addAttribute("user", user);
        return "show4";
    }

    @GetMapping("show5")
    public String show5(Model model){
        model.addAttribute("today", new Date());

        User user = new User();
        user.setAge(21);
        user.setName("Jack Chen");
        model.addAttribute("user",user);
        return "show5";
    }


    @GetMapping("show6")
    public String show6(Model model){

        User user = new User();
        user.setAge(21);
        user.setName("Jack Chen");

        model.addAttribute("users", Arrays.asList(user,user,user,user,user,user,user));

        return "show6";
    }

    @GetMapping("show8")
    public String show8(Model model){

        User user = new User();
        user.setAge(21);
        user.setName("Jack Chen");

        String strs[] = {"a","b","c","d"};

        model.addAttribute("user",user);
        model.addAttribute("age",30);
        model.addAttribute("strs",strs);

        return "show8";
    }
}
